let staffSelect = {
    init(itemId, selectJson, selectId, options) {
        if (options == null) {
            options = new Object();
            options.radio = false;
        }
        if (selectJson != null) {
            selectJson = JSON.parse(selectJson);
            for (let i = 0; i < selectJson.length; i++) {
                selectJson[i].name = selectJson[i].text;
            }
        }
        var selectPageSize = 100;
        var selectItem = xmSelect.render({
                el: ('#' + itemId),
                autoRow: true,
                radio: options.radio,
                toolbar: {
                    show: true,
                    list: ['ALL', 'CLEAR', 'REVERSE']
                },
                filterable: true,
                tips: "-选择-",
                size: 'mini',
                initValue: selectJson,
                paging: false,
                //加上后搜索才显示
                remoteSearch: true,
                //pageSize: selectPageSize,
                pageRemote: true,
                model: {
                    label: {
                        type: 'block',
                        block: {
                            //最大显示数量, 0:不限制
                            showCount: 1,
                            //是否显示删除图标
                            showIcon: true,
                        }
                    }
                },
                on: function (data) {
                    //arr:  当前多选已选中的数据
                    var arr = data.arr;
                    //change, 此次选择变化的数据,数组
                    var change = data.change;
                    //isAdd, 此次操作是新增还是删除
                    var isAdd = data.isAdd;
                    //可以return一个数组, 代表想选中的数据
                    //return []
                    console.log(arr);

                },
                remoteMethod: function (val, cb, show, pageIndex) {
                    //这里如果val为空, 则不触发搜索
                    if (val == "") {
                        return cb([]);
                    }
                    getIndustryAjax(itemId, cb, val, pageIndex, selectPageSize, selectId)
                },
            },
        );
    }
};

/**
 * 远程加载数据
 * @param itemId
 * @param typeId
 * @param cb
 * @param tagName
 * @param pageIndex
 * @param pageSize
 */
function getIndustryAjax(itemId, cb, keyWord, pageIndex, pageSize, selectId) {
    var url = "/brs/engineer/rule/listStaffVtBySimpleQueryDIO";
    $.ajax({
        async: true,
        type: "POST",
        url: url,
        dataType: "json",
        data: {keyword: keyWord, pageIndex: pageIndex, pageSize: pageSize},
        success: function (json) {
            var list = new Array();
            var resData = json.data;
            //var total = 1;
            var pageNum = 1;
            if (resData != null) {
                for (let i = 0; i < resData.length; i++) {
                    var item = new Object();
                    item.name = resData[i].text;
                    item.value = resData[i].value;
                    if (selectId != null && item.value == selectId) {
                        item.selected = true;
                    }
                    list.push(item)
                }
            }
            if (cb != null) {
                cb(list, pageNum);
            }

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            var t = errorThrown;
        }
    })

}


/**
 * 获取选中list的值
 * @param data 数据
 * @returns 选中的结果对象
 */
function getSelectItem(id) {
    var data = xmSelect.get('#' + id, true).getValue();
    var list = new Array();
    if (data != null) {
        var node = null;
        var item = null;
        if (data != null) {
            for (let i = 0; i < data.length; i++) {
                item = data[i];
                node = new Object();
                node.value = parseInt(item.value);
                node.text = item.text;
                if (node.text == null) {
                    //兼容name
                    node.text = item.name;
                }
                list.push(node);
            }
        }
    }
    return list
}

function getSelectItemByKeyValue(id) {
    var data = xmSelect.get('#' + id, true).getValue();
    var list = new Array();
    if (data != null) {
        var node = null;
        var item = null;
        if (data != null) {
            for (let i = 0; i < data.length; i++) {
                item = data[i];
                node = new Object();
                node.value = item.key;
                node.text = item.value;
                list.push(node);
            }
        }
    }
    return list
}

/**
 * 获取选项Id字符串
 * @param data
 * @returns {string}
 */
function getSelectItemIdStr(data) {
    var list = new Array();
    if (data != null) {
        for (let i = 0; i < data.length; i++) {
            var item = data[i];
            list.push(item.value);
        }
    }
    return list.join(',');
}

/**
 *
 */
function getSelectItemId(itemId) {
    var selectItem = xmSelect.get('#' + itemId, true);
    var selectArr = selectItem.getValue('valueStr');
    return selectArr;
}

/**
 * 构建参数
 */
function buildSelectPara(value, text) {
    if (value != null && value != "") {
        var list = new Array();
        var obj = new Object();
        obj.text = text;
        obj.value = value;
        list.push(obj);
        return JSON.stringify(list);
    }
    return null;
}

/**
 * 清空值
 * @param itemId
 */
function clearSelect(itemId) {
    var selectItem = xmSelect.get('#' + itemId, true);
    selectItem.setValue([]);
}